package com.minisoft.workhour.model;

import lombok.Data;
import java.util.List;

/**
 * 工时请求模型
 */
@Data
public class ManhourRequest {

    private List<ManhourItem> manhours;

    public ManhourRequest() {}

    public ManhourRequest(List<ManhourItem> manhours) {
        this.manhours = manhours;
    }

    /**
     * 工时项模型
     */
    @Data
    public static class ManhourItem {

        /**
         * 模式，固定为"detailed"
         */
        private String mode = "detailed";

        /**
         * 所有者
         */
        private String owner;

        /**
         * 任务编号
         */
        private String task;

        /**
         * 类型，固定为"recorded"
         */
        private String type = "recorded";

        /**
         * 开始时间（秒级时间戳）
         */
        private long start_time;

        /**
         * 工时（小时数*100000）
         */
        private long hours;

        /**
         * 工作描述
         */
        private String description;

        public ManhourItem() {}

        public ManhourItem(String mode, String owner, String task, String type, long startTime, long hours, String description) {
            this.mode = mode;
            this.owner = owner;
            this.task = task;
            this.type = type;
            this.start_time = startTime;
            this.hours = hours;
            this.description = description;
        }

        /**
         * 从WorkItem创建ManhourItem
         */
        public static ManhourItem fromWorkItem(WorkItem workItem) {
            return new ManhourItem(
                "detailed",
                "MV8nFvTS",
                workItem.getTaskId(),
                "recorded",
                workItem.getStartTimeForApi(),
                workItem.getHoursForApi(),
                workItem.getDescription()
            );
        }
    }
}
